package com.wangkm.roomdemo

import android.arch.persistence.room.*

/**
 * @author: created by wangkm
 * @Time: 2020/9/15 11:47
 * @Des： $
 * @Email: 1240413544@qq.com
 */
@Dao
interface UserDao {
    //所有的CURD根据primary key进行匹配
//------------------------query------------------------
    @get:Query("SELECT * FROM user")
    val all: List<User?>?

    @Query("SELECT * FROM user WHERE uid IN (:userIds)")
    fun loadAllByIds(userIds: IntArray?): List<User?>?

    @Query("SELECT * FROM user WHERE first_name LIKE :first AND "
            + "last_name LIKE :last LIMIT 1")
    fun findByName(first: String?, last: String?): User?

    @Query("SELECT * FROM user WHERE uid = :uid")
    fun findByUid(uid: Int): User?

    //-----------------------insert----------------------
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(user: User?): Long?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertAll(vararg users: User?): List<Long?>?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertAll(users: List<User?>?): List<Long?>?

    //---------------------update------------------------
    @Update
    fun update(user: User?): Int

    @Update
    fun updateAll(vararg user: User?): Int

    @Update
    fun updateAll(user: List<User?>?): Int

    //-------------------delete-------------------
    @Delete
    fun delete(user: User?): Int

    @Delete
    fun deleteAll(users: List<User?>?): Int

    @Delete
    fun deleteAll(vararg users: User?): Int
}